﻿using System;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Windows;

using Perseus.Plugins;

using Hetymine.Executioner.Commands;

namespace Hetymine.Executioner.Plugins.General.MD5 {
    public class MD5 : Plugin, IExecutable {
        public MD5() {
            this.PluginInfo = PluginInfo.FromAssembly(
                "MD5",
                this.GetType().Assembly,
                "Blake Hancock",
                "http://hetymine.com/executioner/plugins/general/md5/"
            );

            this.CallStrings = new List<string>();
            this.CallStrings.Add("md5");
        }
        #region IExecutable Members
        public List<string> CallStrings { get; set; }
        public ExecutionResult Execute(string parameters) {
            byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(parameters);
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

            byte[] hash = md5.ComputeHash(inputBytes);
            string hashString = string.Empty;

            for (int i = 0; i < hash.Length; i++) {
                hashString += Convert.ToString(hash[i], 16).PadLeft(2, '0');
            }

            Clipboard.SetText(hashString.PadLeft(32, '0'));

            return ExecutionResult.Success;
        }
        #endregion
    }
}
